package com.rsk.api;


import javax.ws.rs.QueryParam;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.SysDeptService;
import com.rsk.utils.result.Result;
import com.rsk.utils.result.ResultBuilder;
import com.rsk.utils.result.ResultCode;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value="/sys/dept")
public class SystemDeptApi {
	
	@Reference(interfaceClass = SysDeptService.class, protocol = "dubbo")
	private SysDeptService sysDeptService;


	//部门保存
	//@RequiresPermissions("sys_users:save")   //权限，暂时不用
	@PostMapping(value="/saveSysDept" )
	public Result<String> saveSysDept(@QueryParam("deptName") String deptName,
		   							  @QueryParam("deptCode") String deptCode,
		   							  @QueryParam("pId") Long pId,
		   							  @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysDeptService.saveSysDept(deptName, deptCode, pId, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}

	//部门修改
	//@RequiresPermissions("sys_users:update")
	@PostMapping(value="/updateSysDept" )
	public Result<String> updateSysDept(@QueryParam("id") Long id,
									    @QueryParam("deptName") String deptName,
									    @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysDeptService.updateSysDept(id, deptName, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	//部门删除
	//@RequiresPermissions("sys_users:del")
	@PostMapping(value="/delSysDept" )
	public Result<String> delSysDept(@QueryParam("id") Long id,
									 @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysDeptService.delSysDept(id, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}


	// 通过部门编号查询部门是否重复
	//@RequiresPermissions("sys_users:del")
	@PostMapping(value = "/selectSysDeptByDeptCode")
	public Result <List<Map<String, Object>>> selectSysDeptByDeptCode(@QueryParam("deptCode") String deptCode){

        //数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
        List<Map<String, Object>> maps = sysDeptService.selectSysDeptByDeptCode(deptCode);
        return ResultBuilder.success(maps,ResultCode.SUCCESS);
	}
	
}
